///**
// * @ProjectName: 
// * @Copyright: 2014 lisheng  All Right Reserved.
// * @address: toughheart@163.com
// * @date: 2015年10月12日 下午8:20:17
// * @Description: 本内容未经本人允许禁止使用、转发.
// */
//
//package com.ls.fw.web.file.controller;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.context.request.WebRequest;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest;
//import org.springframework.web.servlet.ModelAndView;
//
//import com.ls.fw.commons.core.bean.RestStatus;
//import com.ls.fw.commons.core.bean.ResultObj;
//import com.ls.fw.commons.core.utils.file.FileUtil;
//import com.ls.fw.mvc.springmvc.support.annotation.PathVariables;
//import com.ls.fw.web.core.servlet.utils.HttpUtils;
//import com.ls.fw.web.file.bean.DownInfo;
//import com.ls.fw.web.file.bean.FileErrorInfo;
//import com.ls.fw.web.file.bean.FileInfo;
//import com.ls.fw.web.file.bean.FileLimit;
//import com.ls.fw.web.file.constant.Global;
//import com.ls.fw.web.file.support.handler.DefaultUploadHandler;
//import com.ls.fw.web.file.support.handler.UploadHandler;
//
///**
// * 文件控制器 初始化参数： 根目录："baseDir"; 是否为绝对路径："isAbsolutePath"; 文件临时路径："tempdir";
// * 单个最大文件大小："maxFileSize"; 最大内存大小："maxMemSize"; 允许上传的类型（多个用“,”分割）："allowType";
// * 不允许上传的类型（多个用“,”分割）："denyType";
// * 
// * @author lisheng
// * @date 2015年10月12日 下午8:20:17
// * @version V1.0
// */
//@Controller
//@RequestMapping(value = "/file")
//public class FileController extends BaseFileController{
//
//	protected UploadHandler hander = new DefaultUploadHandler();
//	@RequestMapping(value = "/" + DOWNLOAD+"1"+"/**")
//	public Object downloads(HttpServletRequest request
//			, @PathVariables(value="path") String path
//			, String name,HttpServletResponse response)
//			throws IOException { 
//	    	String f = fileLimit.getBaseDir()+File.separator+path;
//	         InputStream inputStream = new FileInputStream(new File(f));
//	         HttpUtils.encode(request, response, name);
//	         down(inputStream, response);  
//	        return null;
//	    }
//
//	/**
//	 * 下载文件
//	 */
//	@RequestMapping(value = "/" + DOWNLOAD+"/**")
//	public ResponseEntity<byte[]> downloads(HttpServletRequest request
//			, @PathVariables(value="path") String path
//			, String name)
//			throws IOException {
//		String savename = name;
//		if(StringUtils.isBlank(savename)){
//			savename = FileUtil.getFileName(path);
//		}
//		String f = fileLimit.getBaseDir()+File.separator+path;
//		File f1 = new File(f);
//		if(!f1.exists()){
//			this.logger.error("文件"+f1.getPath()+"不存在！");
//		}
//		FileInputStream is = new  FileInputStream(f1);
//		return super.download(request, savename, is);
//	}
//	
//	@RequestMapping("/" + UPLOAD)
//	public ModelAndView upload(DefaultMultipartHttpServletRequest request,
//			HttpServletResponse response, WebRequest webRequest)
//			throws Exception {
//    	RequestMapping requestMapping = this.getClass().getAnnotation(RequestMapping.class);
//    	final String pathString = requestMapping.value()[0]+"/"+DOWNLOAD;
//    	return this.doUpload(request, webRequest,"", new UploadWorkHandler() {
//
//			@Override
//			public ResultObj doWork(DefaultMultipartHttpServletRequest request,
//					WebRequest webRequest) throws Exception {
//				final ResultObj obj = ResultObj.newInstance();
//				try {
//					final Map<String, Object> map = new HashMap<String, Object>();
//					final List<FileErrorInfo> fail = new ArrayList<FileErrorInfo>();
//					final List<FileInfo> success = new ArrayList<FileInfo>();
//						uploadHandler(request, new FileUploadHandler() {
//
//							@Override
//							public FileInfo save(String fileFieldName, MultipartFile file,
//									HttpServletRequest request) throws Exception {
//								FileInfo fileInfo = null;
//								String dir = getSaveRelativeDir(request);
//
//								String downloadBaseUrl = getDownloadBaseUrl(request, pathString);
//								fileInfo = saveFile(request,file, dir, file.getOriginalFilename(),downloadBaseUrl);
//								
//								return fileInfo;
//							}
//
//							@Override
//							public void fail(Exception e, String fileFieldName,
//									MultipartFile file,
//									HttpServletRequest request)
//									throws Exception {
//								FileErrorInfo info = new FileErrorInfo();
//								info.setFileName(file.getOriginalFilename());
//								info.setFieldName(fileFieldName);
//								info.setMsg(e.getMessage());
//								fail.add(info);
//							}
//
//							@Override
//							public void success(FileInfo fileInfo,
//									String fileFieldName, MultipartFile file,
//									HttpServletRequest request)
//									throws Exception {
//								success.add(fileInfo);
//							}
//
//							@Override
//							public void check(FileLimit fileLimit,
//									MultipartFile file,
//									HttpServletRequest request)
//									throws Exception {
//								isValid(fileLimit, file, request );
//							}
// 
//						});
//					map.put("fail", fail);
//					map.put("success", success);
//					obj.setData(map);
//					obj.setStatus(RestStatus.OK);
//				} catch (Exception e) {
//					logger.error(e.getMessage(), e);
//					obj.setMsg(e.getMessage());
//				}
//				return obj;
//			}
//		});
//	}
//}
